#ifndef __VIDEO_DECODE_H__
#define __VIDEO_DECODE_H__

#include <map>
#include <mutex>
#include <functional>
#include "Pal/VideoDec.h"
#include "json.h"


namespace Media{

class VideoDecode{
public:
	static int getVideoDecChannel(void);

	static VideoDecode *instance(int channel);

	bool getFormat(VideoDecFormat *format);

	bool setFormat(VideoDecFormat* format);

	//bool setFormat(const Json::Value &table);

	bool start();

	bool stop();

	bool putPacket(VideoDecPacket *packet);

	bool setStreamDisplayChn(int channel);

	
private:
	VideoDecode(int channel);

	bool createDecoder();

	bool decodeInit();

	//void parseConfig(const Json::Value& config, VideoDecFormat& format);

	//bool onConfig(const Json::Value &newTable, const Json::Value &oldTable = Json::Value::null, int &result = Config::result_null);

	//bool onConfigVerify(const Json::Value &newTable, const Json::Value &oldTable = Json::Value::null, int &result = Config::result_null);

	//void ThreadProc(Fdt::Thread *thread);
	
private:
    static std::mutex 			            sm_cntMutex;

    static int                              sm_decodeCnt;
    
	static std::map<int, VideoDecode *> 	sm_decoderMap;

	static std::recursive_mutex 			sm_mapMutex;

	VideoDecFormat							m_format;
	
	VideoDecoder *							m_videoDecoder = nullptr;
	
	int 									m_channel = 0;
	
	bool									m_started = false; //start作为启动标志,避免多个业务多次启停

/*
	std::string								_configName{"Encode.Video.Chn"};
	Json::Value								_config;
	//start作为启动标志,避免多个业务多次启停
	bool									_started = false;
	//_run作为运行标志,某些使能情况下不能去获取帧,例如设置格式重更新启停的时候
	VideoDecFormat							_format;
	bool									_setting = false;
	VideoDecoder *							_videoEncoder = nullptr;
	int 									_channel = 0;
	std::recursive_mutex 					_mutex;
	std::map<void *, std::shared_ptr<CallBack>> 	_func_map;
	Fdt::Thread 						_thread{"Video0"};//thread放在最后,保证thread最后构造,最先析构
*/
};

}//namespace Media
#endif


